package org.com.money.core;

import org.com.money.api.GetMoneyService;
import org.com.money.componet.BankCompment;
import org.com.money.componet.Msg;
import org.com.money.domain.User;
import org.com.money.dto.GetMoneyDTO;
import org.com.money.service.MoneyException;

public class GetMoneyServiceImpl implements GetMoneyService {

	private transient BankCompment bankCompment = new BankCompmentImpl();

	@Override
	public void getMoney(GetMoneyDTO dto) throws MoneyException {

		// 尚未登入
		if (dto.getUser() == null) {
			throw new MoneyException(Msg.W001);

		}
		this.bankCompment.getMoney(dto.getUser(), dto.getDrawWith());

	}

	@Override
	public void logout(GetMoneyDTO dto) throws MoneyException {

		//並無登入
		if (dto.getUser() == null) {
			throw new MoneyException(Msg.W001);
		}

		dto.setUser(null);

	}

	@Override
	public void login(GetMoneyDTO dto) throws MoneyException {

		if (dto.getUser() == null) {
			final User user = this.bankCompment.login(dto.getId(),
					dto.getPassword());

			System.out.println("user=" + user);
			dto.setUser(user);
		} else {
			System.out.println("已經登入！");
			throw new MoneyException(Msg.W003);
		}

	}
}
